#ifndef __TOUCH_H__
#define __TOUCH_H__
#include <stdio.h>
#include <dlfcn.h>  // 动态加载动态库的头文件：dlopen()、dlsym()
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include <sys/ioctl.h>
#include <linux/input.h> 
#include"lvgl/lvgl.h"
// BMP格式头规范
struct bitmap_header
{
	int16_t type;
	int32_t size; // 图像文件大小
	int16_t reserved1;
	int16_t reserved2;
	int32_t offbits; // bmp图像数据偏移量
}__attribute__((packed));

struct bitmap_info
{
	int32_t size;   // 本结构大小
	int32_t width;  // 图像宽
	int32_t height; // 图像高
	int16_t planes;

	int16_t bit_count; // 色深
	int32_t compression;
	int32_t size_img; // bmp数据大小，必须是4的整数倍
	int32_t X_pel;
	int32_t Y_pel;
	int32_t clrused;
	int32_t clrImportant;
}__attribute__((packed));

// bitmap_info.compression为真
struct rgb_quad
{
	int8_t blue;
	int8_t green;
	int8_t red;
	int8_t reserved;
}__attribute__((packed));


// LCD的结构
typedef struct LCD{
	int fd;
	int width;
	int height;
	int bpp;
	int row_size;
	int size;
	char *fbmem;
}LCD;

// BMP的结构
typedef struct BMP{
	int width;
	int height;
	int bpp;
	int row_size;	//不含pad的字节数
	int pad;	//填充多少
	int size;	// size_img
	char *rgb;
}BMP;
// 触摸屏可能的操作
typedef enum TouchScreenAction{
	CLICK = 0,
	SLIDE_LEFT,
	SLIDE_RIGHT,
	SLIDE_DOWN,
	SLIDE_UP
}TouchScreenAction;


// 触摸屏结构设计
typedef struct TouchScreen{
	int fd;
	struct input_absinfo abs_x;
	struct input_absinfo abs_y;
}TouchScreen;

// 坐标结构
typedef struct Coordinate
{
	int x;
	int y;
	TouchScreenAction action;
}Coordinate;

extern void touchscreen_init(TouchScreen *ts);
extern void touchscreen_uninit(TouchScreen *ts);
extern void ts_press(Coordinate *coor, TouchScreen *ts);
extern void ts_loosen(Coordinate *coor, TouchScreen *ts);
extern void anybmp(int xoff, int yoff, const char *bmpname, LCD *lcd);
void myphoto_example(void);
#endif